package com.googlecode.continuity.plugin.gwtext.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.*;
import com.googlecode.continuity.plugin.gwtext.client.message.GWTExtensionMessages;

/**
 * ContentBox
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public abstract class ContentBox extends CenteredDialogBox {
  private Label statusMessage;
  private Label error;
  protected ScrollPanel contentContainer;
  protected Button close;

  private final GWTExtensionMessages messages = (GWTExtensionMessages) GWT.create(GWTExtensionMessages.class);

  public ContentBox() {
    // set up content area
    contentContainer = new ScrollPanel();
    frame.insert(contentContainer, frame.getWidgetIndex(buttons));

    // set up bottom control bar
    statusMessage = new Label();
    buttons.add(statusMessage);
    error = new Label();
    buttons.add(error);
    close = new Button(messages.close());
    buttons.add(close);

    // set styles
    addStyleName("contentBox");
    contentContainer.addStyleName("contentContainer");
    close.addStyleName("close");
    error.addStyleName("error");
    statusMessage.addStyleName("statusMessage");
    buttons.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_RIGHT);
    buttons.setCellWidth(close, "100%");
    buttons.setWidth("100%");
    error.setVisible(false);
    error.setWordWrap(false);
    statusMessage.setVisible(false);
    statusMessage.setWordWrap(false);
    buttons.setCellVerticalAlignment(error, HasVerticalAlignment.ALIGN_MIDDLE);
    buttons.setCellVerticalAlignment(statusMessage, HasVerticalAlignment.ALIGN_MIDDLE);

    // set close action
    close.addClickListener(finished);
  }

  protected void showError(String message) {
    error.setText(messages.errorOccured() + message);
    error.setVisible(true);
  }

  protected void showStatusMessage(String message) {
    statusMessage.setText(message);
    statusMessage.setVisible(true);
  }

  protected void hideStatusMessage() {
    statusMessage.setVisible(false);
  }
}
